#ifndef _CORE_CONFIG_H_
#define _CORE_CONFIG_H_

#include <stdio.h>
#include <deque>

class tConfig;

class tSection
{
	char * sec_name;
	std::deque<std::pair<char*, char*>> opts;
	void clear();
	void reset();
public:	
	tSection();
	~tSection();

	bool GetOptInt(const char * opt, int * val);
	char * GetOptStr(const char * opt);

	friend class tConfig;
};

class tConfig
{
	FILE *file;
	std::deque<std::pair<char*,char*>> opts;
	std::deque<tSection> sections;
	tSection m_CurSec;

	int SkipSpaceChar(char ** buf);
	bool EndOfLine(char *buf);
	int ReadWord(char **buf, char ** word);
	int ParseLine(char ** option, char ** value);
	int ParseSectionName(const char * buf);
public:
	tConfig();
	~tConfig();

	int LoadConfig(const char * configfile);
	bool GetOptInt(const char * opt, int * val);
	char * GetOptStr(const char * opt);
	int SetConfig(int index, char * strval);
	tSection* GetSection(const char * sec_name);
};



#endif
